import Mock from "mockjs";

Mock.setup({
  timeout: "1000-2000", // 所有请求延迟 500ms~2000ms
});

// 用户信息
const info = () => {
  return {
    code: 200,
    msg: "Successful",
    data: {
      adminId: 1,
      name: "admin",
      avatar: "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
      introduction: "后台",
      roles: ["admin"],
    },
  };
};

// 1. 延时 1.5 秒的接口（可改）
Mock.mock(new RegExp("/api.*"), "get", info);

// 2. 50% 概率返回 500，用于重试测试
// Mock.mock("/api/retry", "get", () => {
//   const ok = Math.random() > 0.5;
//   return Mock.mock({
//     code: 0,
//     data: ok ? { ok: 1 } : null,
//     msg: ok ? "" : "mock server error",
//   });
// });
